package fragmentson;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.wq.cycling.R;

import java.util.ArrayList;

import activity.SonActivity;
import bean.EntityForSimple;
import fragmentson.backhandle.BackHandledFragment;
import util.adapter.DevicesAdapter;
import util.myview.springview.DefaultFooter;
import util.myview.springview.DefaultHeader;
import util.myview.springview.SpringView;

/**
 * 我要报失选择设备页
 * author：wangqi on 2017/4/26 17:48
 * email：773630555@qq.com
 */
public class ReportLoss_C extends BackHandledFragment {

	private View rootView;
	private ListView lv_devices;
	private Intent intent;
	private Bundle bundle;
	private DevicesAdapter adapter;

	private SpringView springView;
	private ArrayList<EntityForSimple> mDatas = new ArrayList<>();
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		rootView = getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_reportloss_c, null);
		initView();
		return rootView;
	}

	public void initView(){
		((TextView) rootView.findViewById(R.id.tv_title)).setText(R.string.title_mycar);
		mDatas.add(new EntityForSimple());
		mDatas.add(new EntityForSimple());
		mDatas.add(new EntityForSimple());
		lv_devices = ((ListView) rootView.findViewById(R.id.lv_devices));
		adapter = new DevicesAdapter(getActivity(),mDatas);
		lv_devices.setAdapter(adapter);
		lv_devices.setOnItemClickListener(new AdapterView.OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
				((SonActivity) getActivity()).addFragment(ReportLoss_D.newInstance());
			}
		});
		initSpringView();
	}

	/**
	 * 初始化springview组件
	 */
	private void  initSpringView(){
		springView = (SpringView) rootView.findViewById(R.id.springview);
		springView.setType(SpringView.Type.FOLLOW);
		springView.setListener(new SpringView.OnFreshListener() {
			@Override
			public void onRefresh() {
				new Handler().postDelayed(new Runnable() {
					@Override
					public void run() {
						springView.onFinishFreshAndLoad();
					}
				}, 1000);
			}

			@Override
			public void onLoadmore() {
				new Handler().postDelayed(new Runnable() {
					@Override
					public void run() {
						springView.onFinishFreshAndLoad();
					}
				}, 1000);
			}
		});
		springView.setHeader(new DefaultHeader(getActivity()));
		springView.setFooter(new DefaultFooter(getActivity()));
	}

	public static ReportLoss_C newInstance() {
		ReportLoss_C fragment = new ReportLoss_C();
		return fragment;
	}


	@Override
	public boolean onBackPressed() {
		return false;
	}
	
}
